using System;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using Common;
using Common.Enum;

namespace Converters
{
	public class StringConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value == null || value == DependencyProperty.UnsetValue)
			{
				return null;
			}
			if (value is ETemperatureControlMode)
			{
				switch ((ETemperatureControlMode)value)
				{
				case ETemperatureControlMode.Module:
					return Utility.GetMessage("module_control");
				case ETemperatureControlMode.Tube:
					return Utility.GetMessage("tube_control");
				case ETemperatureControlMode.Fast:
					return Utility.GetMessage("fast_control");
				default:
					return value;
				}
			}
			if (value is EHRMTypeMethod)
			{
				return (from s in EnumManagement.GetAllHRMTypeMethod()
					where (EHRMTypeMethod)s.Key == (EHRMTypeMethod)value
					select s.Value).FirstOrDefault();
			}
			if (value is EHRMClassificationMethod)
			{
				return (from s in EnumManagement.GetAllClassificationMethod()
					where (EHRMClassificationMethod)s.Key == (EHRMClassificationMethod)value
					select s.Value).FirstOrDefault();
			}
			if (value is EADTypeMethod)
			{
				return (from s in EnumManagement.GetAllADTypeMethod()
					where (EADTypeMethod)s.Key == (EADTypeMethod)value
					select s.Value).FirstOrDefault();
			}
			if (value is EOperator)
			{
				return (from s in EnumManagement.GetAllOperator()
					where (EOperator)s.Key == (EOperator)value
					select s.Value).FirstOrDefault();
			}
			if (value is ECalcResult)
			{
				if ((ECalcResult)value == ECalcResult.None)
				{
					return null;
				}
				return (from s in EnumManagement.GetAllCalcResult()
					where (ECalcResult)s.Key == (ECalcResult)value
					select s.Value).FirstOrDefault();
			}
			if (value is EPeekType)
			{
				return (from s in EnumManagement.GetAllPeekType()
					where (EPeekType)s.Key == (EPeekType)value
					select s.Value).FirstOrDefault();
			}
			if (value is EDigitalFilter)
			{
				return (from s in EnumManagement.GetAllDigitalFilter()
					where (EDigitalFilter)s.Key == (EDigitalFilter)value
					select s.Value).FirstOrDefault();
			}
			return Utility.GetMessage(value.ToString());
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return value;
		}
	}
}
